﻿@model CustomerInfoModel

@using SmartStore.Web.Models.Customer;

@{
	Html.AddTitleParts(T("PageTitle.Account").Text);

	Layout = "_MyAccount";
	ViewBag.PageClassToken = "info";
	ViewBag.PageTitle = T("Account.CustomerInfo").Text;
}

@using (Html.BeginForm("Info", "Customer", FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()

    if (!ViewData.ModelState.IsValid)
    {
        @Html.ValidationSummary(true, "", new { @class = "alert alert-danger" })
    }

    <fieldset class="content-group">
        <legend><span>@T("Account.YourPersonalDetails")</span></legend>

        @if (Model.GenderEnabled)
        {
            <div class="form-group row">
                <label class="col-lg-3 col-form-label">@T("Account.Fields.Gender")</label>
                <div class="col-lg-9 form-inline">
					<div class="form-check form-check-inline">
						@Html.RadioButton("Gender", "M", (Model.Gender == "M"), new { @class = "form-check-input", id = "gender-male" })
						<label class="form-check-label" for="gender-male">@T("Account.Fields.Gender.Male")</label>
					</div>
					<div class="form-check form-check-inline">
						@Html.RadioButton("Gender", "F", (Model.Gender == "F"), new { @class = "form-check-input", id = "gender-female" })
						<label class="form-check-label" for="gender-female">@T("Account.Fields.Gender.Female")</label>
					</div>
                </div>
            </div>
        }

		@if (Model.TitleEnabled)
		{
			@Html.ControlGroupFor(model => model.Title, required: false, breakpoint: "lg")
		}

        @Html.ControlGroupFor(model => model.FirstName, required: true, breakpoint: "lg")
        @Html.ControlGroupFor(model => model.LastName, required: true, breakpoint: "lg")

        @if (Model.DateOfBirthEnabled)
        {
            <div class="form-group row">
                <label class="col-lg-3 col-form-label" for="DateOfBirthDay">@T("Account.Fields.DateOfBirth")</label>
                <div class="col-lg-9">
                    @Html.DatePickerDropDowns(Html.FieldNameFor(x => x.DateOfBirthDay),
                            Html.FieldNameFor(x => x.DateOfBirthMonth),
                            Html.FieldNameFor(x => x.DateOfBirthYear),
                            DateTime.Now.Year - 110,
                            DateTime.Now.Year,
                            Model.DateOfBirthDay,
                            Model.DateOfBirthMonth,
                            Model.DateOfBirthYear)
                    @Html.ValidationMessageFor(model => model.DateOfBirthDay)
                    @Html.ValidationMessageFor(model => model.DateOfBirthMonth)
                    @Html.ValidationMessageFor(model => model.DateOfBirthYear)
                </div>
            </div>
        }

        @Html.ControlGroupFor(model => model.Email, required: true, breakpoint: "lg")

        @if (Model.UsernamesEnabled)
        {
            <div class="form-group row">
                @Html.LabelFor(model => model.Username, new { @class = "col-lg-3 col-form-label required", @for = "Username" })
                @if (Model.AllowUsersToChangeUsernames)
                {
                    <div class="col-lg-9">
                        @if (Model.CheckUsernameAvailabilityEnabled)
                        {
                            <div class="input-group">
                                @Html.TextBoxFor(model => model.Username, new { @class = "form-control" })
                                @{ Html.RenderPartial("_CheckUsernameAvailability"); }
                            </div>
                        }
                        else
                        {
                            @Html.TextBoxFor(model => model.Username, new { @class = "form-control" })
                        }
                        @Html.ValidationMessageFor(model => model.Username)
                    </div>
                }
                else
                {
                    <div class="col-lg-9">
						<div class="form-control-plaintext">@Model.Username</div>
					</div>
				}
            </div>
        }

        @if (Model.DisplayCustomerNumber)
        {
			var customerNumberAttributes = !Model.CustomerNumberEnabled ? (object)(new { @class = "form-control", @readonly = "true" }) : (object)(new { @class = "form-control" });
            <div class="form-group row">
                @Html.LabelFor(model => model.CustomerNumber, new { @class = "col-lg-3 col-form-label", @for = "CustomerNumber" })
                <div class="col-lg-9">
                    @Html.TextBoxFor(model => model.CustomerNumber, customerNumberAttributes)
                </div>
            </div>
        }

    </fieldset>

	if (Model.AssociatedExternalAuthRecords.Count > 0)
	{
        <fieldset class="content-group">
            <legend><span>@T("Account.AssociatedExternalAuth")</span></legend>

			<div class="table-responsive">
				<table class="table table-hover border-top-0">
					<thead>
						<tr>
							<th class="border-top-0">
								@T("Account.AssociatedExternalAuth.AuthMethodName")
							</th>
							<th class="border-top-0">
								@T("Account.AssociatedExternalAuth.Email")
							</th>
							<th class="border-top-0">
								@T("Account.AssociatedExternalAuth.ExternalIdentifier")
							</th>
						</tr>
					</thead>
					<tbody>
						@foreach (var item in Model.AssociatedExternalAuthRecords)
						{
							<tr>
								<td>
									@item.AuthMethodName
								</td>
								<td>
									@item.Email
								</td>
								<td>
									@item.ExternalIdentifier
								</td>
							</tr>
						}
					</tbody>
				</table>
			</div>
		</fieldset>
    }

    if (Model.CompanyEnabled || Model.DisplayVatNumber)
    {
        <fieldset class="content-group">
            <legend><span>@T("Account.CompanyDetails")</span></legend>

            @if (Model.CompanyEnabled)
            {
                @Html.ControlGroupFor(model => model.Company, required: Model.CompanyRequired, breakpoint: "lg")
            }
            @if (Model.DisplayVatNumber)
            {
                <div class="form-group row">
                    @Html.LabelFor(model => model.VatNumber, new { @class = "col-lg-3 col-form-label", @for = "VatNumber" })
                    <div class="col-lg-9">
						<div class="input-group">
							@Html.TextBoxFor(model => model.VatNumber, new { @class = "form-control", placeholder = T("Common.Optional") })
							<div class="input-group-append"><span class="input-group-text">@Model.VatNumberStatusNote</span></div>
						</div>
						<div class="form-text text-muted vat-note">@T("Account.Fields.VatNumber.Note")</div>
                    </div>
                </div>
            }
        </fieldset>
    }

    if (Model.StreetAddressEnabled || Model.StreetAddress2Enabled || Model.ZipPostalCodeEnabled || Model.CityEnabled || Model.CountryEnabled)
    {
        <fieldset class="content-group">
            <legend><span>@T("Account.YourAddress")</span></legend>

            @if (Model.StreetAddressEnabled)
            {
                @Html.ControlGroupFor(model => model.StreetAddress, required: Model.StreetAddressRequired, breakpoint: "lg")
            }
            @if (Model.StreetAddress2Enabled)
            {
                @Html.ControlGroupFor(model => model.StreetAddress2, required: Model.StreetAddress2Required, breakpoint: "lg")
            }
            @if (Model.ZipPostalCodeEnabled)
            {
                @Html.ControlGroupFor(model => model.ZipPostalCode, required: Model.ZipPostalCodeRequired, breakpoint: "lg")
            }
            @if (Model.CityEnabled)
            {
                @Html.ControlGroupFor(model => model.City, required: Model.CityRequired, breakpoint: "lg")
            }
            @if (Model.CountryEnabled)
            {
				<div class="form-group row">
					@Html.LabelFor(model => model.CountryId, new { @class = "col-lg-3 col-form-label", @for = "CountryId" })
					<div class="col-lg-9">
						@Html.DropDownList("CountryId", Model.AvailableCountries,
							new { @class = "form-control country-input country-selector",
								data_region_control_selector = "#StateProvinceId",
								data_states_ajax_url = Url.Action("GetStatesByCountryId", "Country"),
								data_addEmptyStateIfRequired = "true"
							})
					</div>
				</div>
			}
            @if (Model.CountryEnabled && Model.StateProvinceEnabled)
            {
                <div class="form-group row">
                    @Html.LabelFor(model => model.StateProvinceId, new { @class = "col-lg-3 col-form-label", @for = "StateProvinceId" })
                    <div class="col-lg-9">
                        @Html.DropDownList("StateProvinceId", Model.AvailableStates, new { @class = "form-control" })
                    </div>
                </div>
            }
        </fieldset>
    }

    if (Model.PhoneEnabled || Model.FaxEnabled)
    {
        <fieldset class="content-group">
            <legend><span>@T("Account.YourContactInformation")</span></legend>

            @if (Model.PhoneEnabled)
            {
                @Html.ControlGroupFor(model => model.Phone, required: Model.PhoneRequired, breakpoint: "lg")
            }
            @if (Model.FaxEnabled)
            {
                @Html.ControlGroupFor(model => model.Fax, required: Model.FaxRequired, breakpoint: "lg")
            }

        </fieldset>
    }

    if (Model.NewsletterEnabled)
    {
        <fieldset class="content-group">
            <legend><span>@T("Account.Options")</span></legend>
            <div class="form-group row">
				<div class="col">
					<div class="form-check">
						@Html.EditorFor(model => model.Newsletter, new { @class = "form-check-input" })
						<label class="form-check-label" for="Newsletter">
							@T("Account.Fields.Newsletter", Url.Topic("PrivacyInfo"))
						</label>
					</div>
				</div>
			</div>
        </fieldset>
    }

    if (Model.AllowCustomersToSetTimeZone || Model.SignatureEnabled)
    {
        <fieldset class="content-group">
            <legend><span>@T("Account.Preferences")</span></legend>

            @if (Model.AllowCustomersToSetTimeZone)
            {
                <div class="form-group row">
                    @Html.LabelFor(model => model.TimeZoneId, new { @class = "col-lg-3 col-form-label", @for = "TimeZoneId" })
                    <div class="col-lg-9">
                        @Html.DropDownList("TimeZoneId", Model.AvailableTimeZones, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.TimeZoneId)
                    </div>
                </div>
            }
            @if (Model.SignatureEnabled)
            {
                <div class="form-group row">
                    @Html.LabelFor(model => model.Signature, new { @class = "col-lg-3 col-form-label", @for = "Signature" })
                    <div class="col-lg-9">
                        @Html.TextAreaFor(model => model.Signature, new { placeholder = T("Common.Optional"), @class = "form-control", rows = "3" })
                    </div>
                </div>
            }
        </fieldset>
    }

    <div class="form-group row">
        <div class="col-12 text-muted">
            @T("Common.FormFields.Required.Hint")
        </div>
    </div>

    <div class="form-group row">
        <div class="col">
            <button type="submit" name="save-info-button" class="btn btn-primary btn-lg save-customer-info-button">
                <i class="fa fa-check"></i>
                <span>@T("Common.Save")</span>
            </button>
        </div>
    </div>
}